<%@ page language="java" contentType="text/html; charset=ISO-8859-1"
	pageEncoding="ISO-8859-1"%>
<%@ page import="java.sql.*"%>
<%@ page import="schronisko.*,Users.*"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1">
<title>Wyszukaj zwierzaka</title>
<link rel="stylesheet" type="text/css" href="styles/forms.css">
<link rel="stylesheet" type="text/css" href="styles/images.css">
<style type="text/css">
body {
	background: #c6b154;
}
</style>
</head>
<body>
	<a href="index.jsp">Powrot na strone glowna</a>
	<br>
	<%
	Queries q = new Queries();
		response.setContentType("text/html");
		if ((Integer) session.getAttribute("search") == 1) {
	%>
	<center>
	<form name="browse" action="Search" method="post"
			class="form-container">
			<input id="all" name="all" type="hidden" value="1">
			<h2>Wyswietlenie bazy zwierzakow</h2>
			<div class="submit-container">
				<input type="submit" value="Wyswietl wszystko" class="submit-button">
			</div>
		</form>
		<form name="search" action="Search" method="post"
			class="form-container">
			<br>
			<h2>Wyszukiwanie zwierzaka</h2>
			<br>
			<div class="form-title">rasa:</div>
			<input id="race" name="race" type="text" size="50" class="form-field"><br>
			<br>
			<div class="form-title">plec:</div>
			<input id="gender" name="gender" type="radio" value="male">
			meski <input id="gender" name="gender" type="radio" value="female">
			zenski<br>
			<br>
			<div class="form-title">Wiek w miesiacach:</div>
			<input id="eq" name="eq" type="radio" value="<"> mniejszy
			<input id="eq" name="eq" type="radio" value="="> rowny <input
				id="eq" name="eq" type="radio" value=">"> wiekszy <br>
			<input id="all" name="all" type="hidden" value="0"> <input
				id="age" name="age" type="text" size="50" class="form-field"><br>

			<br>
			<div class="submit-container">
				<input type="submit" value="Wyszukaj" class="submit-button">
			</div>
		</form>
	</center>
	<%
		} else {
			int ID=0;
			String zmienna = (String) session.getAttribute("all");
			ResultSet r = null;
			if (zmienna.equals("1")) {
				r = (ResultSet) session.getAttribute("allAnimals");
			} else {
				r = (ResultSet) session.getAttribute("animals");
			}
				if (r != null) {
					
					
					out.println("<a href='Search.jsp'>Powrot do wyszukiwania</a><br>");
					String avail = null;
					String plec = null;
					while (r.next()) {
						if(r.getString("gender").equals("male")){
							plec = "M";
						}
						if(r.getString("gender").equals("female")){
							plec= "K";
						}
						if(r.getString("accessibility").equals("available"))
							avail = "DOSTEPNY";
						if(r.getString("accessibility").equals("adopted"))
							avail = "ADOPTOWANY";
							
						if(r.getString("accessibility").equals("pending"))
							avail = "OCZEKUJACY";
						if(r.getString("accessibility").equals("dead"))
							avail = "MARTWY";
						ID = r.getInt("ID_animal");
						String picture = r.getString("pic");
						int dlugosc = picture.length();
						out.println("<div class='image'><div class='main'>"
								+ "Imie: " + r.getString("name") + "<br>"
								+ "Rasa: "+r.getString("race") + "<br>"
								+ "Plec: " + plec + "<br>"
								+ "Data urodzenia: "+ r.getString("date_of_birth") +"<br>"
								+ "Ostatnie szczepienie: "+ r.getString("last_inoculation") +"<br>"
								+ avail + "<br><br>");
						if(avail.equals("DOSTEPNY")){
							String username = null;
							try{
							username = (String)session.getAttribute("username");
							}
							catch(NullPointerException e){
								
							}
							if(username != null){
						out.println("<form action='AdoptAnimal' method='post'>"
								+ "<input id='id' name='id' type='hidden' value=" + ID + ">"
								+ "<input type='submit' value='Adoptuj'></form>" + "<br>");
							}
							else{
								out.println("<form action='Register.jsp' method='post'>"
										+ "<input id='id' name='id' type='hidden' value=" + ID + ">"
										+ "<input type='submit' value='Zaloguj sie, aby moc zaadoptowac tego zwierzaka'></form>" + "<br>");
							}
						}
						out.println("</div><img src='" + picture.substring(3, dlugosc) +"'>"
								+ "<div class='details'>Informacje dodatkowe: <br>"
								+ r.getString("description")+
								"</div></div><br><br><br><br><br><br><br><br><br><br><br><br><br>");
						
					}
					session.setAttribute("search", 1);
				}
				
			
				
			}
	%>
</body>
</html>